﻿@using AtletIS.Shared.Helpers
@model MvcAtletIS.Models.LiveModel
@if (Model != null)
{ 
    <div id="main">
        
        <!-- HEADER -->
        <div class="header-info">
            <p class="float-right">@ViewRes.SharedStrings.ChipViewer</p>
            <p class="align-left"><strong>@Model.ActiveDiscipline.Name</strong></p>
        </div>

        <!-- CHECK POINTS -->
        <div id="col1">
            <ul style="height: 430px;">
                @if (Model.CheckPoints != null && Model.CheckPoints.Count > 0)
                {
                    foreach (var item in Model.CheckPoints)
                    {
                        if (item.ID == Model.ActiveCheckPoint.ID)
                        {
                            <li id="chkActive" style="background: #ddd;">
                                @Html.ActionLink(item.Name, "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = item.ID, Code = Model.Code })
                            </li>
                        }
                        else
                        {
                            <li>
                                @Html.ActionLink(item.Name, "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = item.ID, Code = Model.Code })
                            </li>
                        }
                    }
                }
            </ul>
        </div>
        
        <!-- CHIP DATA -->
        <div id="col2">
            @{
                Html.RenderAction("ChipViewerItemsPartial", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineListId = Model.ActiveDiscipline.ID, CheckPointId = Model.ActiveCheckPoint.ID });
            }
        </div>

    </div>
    
    <script type="text/javascript">

        function refreshChipViewer() {
            $.ajax({
                url: "/Live/ChipViewerItemsPartial?CompetitionId=@Model.ActiveCompetition.ID&DisciplineListId=@Model.ActiveDiscipline.ID&CheckPointId=@Model.ActiveCheckPoint.ID",
                type: "POST",
                dataType: "html",
                success: function (result) {
                    $("#col2").html(result);
                    window.setTimeout("refreshChipViewer();", 3000);
                },
                error: function (error) {
                    alert(error.responseText);
                }
            });
        }

        $(function () {
            $("#col1").animate({
                scrollTop: $("#chkActive").offset().top - $("#col1").offset().top - 3
            }, 0);

            window.setTimeout("refreshChipViewer();", 3000);
        });

    </script>
}